# -*- coding: utf-8 -*-

import json
import time
import os
import sys
import requests
from Log import Log
from Brain import XiaolanBrain

class SkillCommandDo(XiaolanBrain):

    def __init__(self):

        pass

    def SkillInfoTurnToServerInfo(self, json):

        """
        将技能的data转换为发送给client的data
        :param json:
        :return:
        """
        return {
            'ServerEvent': {
                'Header': {
                    'NameSpeace': 'xiaolan.brain.returnback.skill.complete',
                    'ResponesId': 'cgfh',
                    'ResponesFrom': 'XiaolanBrain',
                    'TimeStamp': time.time()
                },
                'ClientSend': json['SkillEvent']['ClientSend']
            },
            'ClientShouldDo': {
                'Skill': {
                    'SkillName': json['SkillCommand']['SkillName'],
                    'OutputSpeech': json['SkillCommand']['outputSpeech'],
                    'TtsService': json['SkillCommand']['TtsService'],
                    'TtsMore': None,
                    'RecordType': json['SkillCommand']['RecordType'],
                    'WaitAnswer': json['SkillCommand']['waitAnswer'],
                    'MoreCommand': None,
                    'AskSlots': {
                        'SlotsName': json['SkillCommand']['AskSlots']['SlotsName'],
                        'SlotsDict': json['SkillCommand']['AskSlots']['SlotsName'],
                        'SlotsAsk': json['SkillCommand']['AskSlots']['SlotsAsk'],
                        'RecordType': json['SkillCommand']['AskSlots']['RecordType']
                    },
                    'ScreenDisplay': self.ScreenDisplayDo(json['SkillCommand']['ScreenDisplay'])
                },
                'System': {
                    'commands': None,
                    'more': None,
                }
            },
            'Debug': {
                'States': None,
                'Requests': {
                    'Type': 'skill.returnback.but.is.auth.from.xiaolan.brain',
                    'Id': '54657546876434898756410134684540564654652044501450871',
                    'TimeStamp': str(time.time())
                }
            }
        }

    def ScreenDisplayDo(self, data):

        Type = data['Type']
        if Type == 'TextDisplay':
            return {
                'Type': Type,
                'Title' : data['Title'],
                'Text': data['Text'],
                'BackgroundImageUrl': data['BackgroundImageUrl'],
                'Remind': data['RemindWord']
            }
        elif Type == 'ImageDisplay':
            return {
                'Type': Type,
                'Title': data['Title'],
                'ImageUrl': data['ImageUrl'],
                'RemindWord': data['RemindWord']
            }
        elif Type == 'VideoDisplay':
            return {
                'Type': Type,
                'Title': data['Title'],
                'VideoUrl': data['VideoUrl'],
                'RemindWord': data['RemindWord']
            }
        elif Type == 'MusicDisplay':
            return {
                'Type': Type,
                'Title': data['Title'],
                'MusicUrl': data['MusicUrl'],
                'BackgroundImageUrl': data['BackgroundImageUrl'],
                'RemindWord': data['RemindWord']
            }
        else:
            return {}